/**
 * 
 */
package com.bitantenna.player;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;

import com.bitantenna.Spot;



public final class PlayerPlayStopListener implements ActionListener {	
	private final Player player;

	public PlayerPlayStopListener(Player player) {	
		this.player = player;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (player.spot().status()==Spot.Status.stopped) radioStart(); else radioStop();				
	}

	public void radioStop() {
		player.getButton_play().setText("Start");
		player.getButton_play().setIcon(new ImageIcon(getClass().getResource("/com/bitantenna/images/media-playback-start.png")));
		player.spot().stopListen();
	}

	public void radioStart() {
		player.getButton_play().setText("Stop");
		player.getButton_play().setIcon(new ImageIcon(getClass().getResource("/com/bitantenna/images/media-playback-stop.png")));				
		player.spot().startListen();
		player.spot().onLog().addObserver(new PlayerLogObserver(player));
		
		player.getLabel_radio_name().setText(""+player.spot().settings().name());
							
	}
}